﻿using DTCash.Logger;
using DTCash.Logger.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTCash.Redis;
using Uranus.Service.ProductService;
using Uranus.Service.UserService;
using Uranus.Service.OtherService;
using Uranus.Service.OrderService;

namespace Uranus.Service
{
    public class Other : BaseData
    {
        private static Other other = null;

        public static Other GetOther()
        {
            if (other == null)
            {
                other = new Other();
            }
            return other;
        }

        /// <summary>
        /// 添加source
        /// </summary>
        /// <param name="sourceRequest"></param>
        /// <returns></returns>
        public SourceResponse InsertSource(SourceRequest sourceRequest)
        {
            OtherServiceClient otherService = new OtherServiceClient();
            try
            {
                return otherService.InsertSource(sourceRequest);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogEnum.Error, "InsertSource 出现异常", ex.Message.ToString(), sourceRequest);
                return new SourceResponse();
            }
            finally
            {
                otherService.Close();
            }
        }

        /// <summary>
        /// 根据id查询配置信息
        /// Date:2016年10月17日10:57:06
        /// Author:Guo
        /// </summary>
        /// <param name="configID"></param>
        /// <returns></returns>
        //public ConfigCenterDTO GetConfigCenterByConfigID(int configID)
        //{
        //    OtherServiceClient otherService = new OtherServiceClient();
        //    try
        //    {
        //        Func<ConfigCenterDTO> method = delegate
        //        {
        //            ConfigCenterDTO response = otherService.GetConfigCenterByConfigID(new ConfigCenterRequest() { ConfigID = configID });
        //            return response;
        //        };
        //        return GetData<ConfigCenterDTO>(method, CacheItem.InitByIdentity(configID.ToString(), "ConfigCenter").Other.Info);
        //    }
        //    catch (Exception ex)
        //    {
        //        LogHelper.WriteLog(LogEnum.Error, "根据id查询配置信息 失败 GetConfigCenterByConfigID", ex.Message.ToString(), null);
        //        return null;
        //    }
        //    finally
        //    {
        //        otherService.Close();
        //    }
        //}
        /// <summary>
        /// 清除缓存
        /// </summary>
        /// <param name="modeulekey"></param>
        /// <param name="inputId"></param>
        /// <returns></returns>
        public Uranus.Service.OtherService.BaseResponse RemoveModuleCache(string modeulekey, string inputId)
        {
            OtherServiceClient otherService = new OtherServiceClient();
            try
            {
                return otherService.RemoveModuleCache(modeulekey, inputId);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogEnum.Error, "清除缓存 失败 RemoveModuleCache", ex.Message.ToString(), null);
                return null;
            }
            finally
            {
                otherService.Close();
            }
        }
    }
}
